﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer.DAL;
using Common;

namespace BestBuy.PublicViews
{
    public partial class SearchAuction : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["CategoryID"] != null)
                {
                    int id = int.Parse(Request.QueryString["CategoryID"]);
                    LoadAuctions(id);
                }
                else if (Request.QueryString["NameSearch"] != null)
                {
                    string name = Request.QueryString["NameSearch"];
                    LoadAuctionsByString(name);
                }
            }
        }

        private void LoadAuctions(int id)
        {
            gvAuctions.DataSource = AuctionDAL.GetOpenAuctionByCategory(id);
            gvAuctions.DataBind();
            gvEndAuctions.DataSource = AuctionDAL.GetEndAuctionByCategory(id);
            gvEndAuctions.DataBind();
        }

        private void LoadAuctionsByString(string NameSearch)
        {
            gvAuctions.DataSource = AuctionDAL.GetAuctionByString(NameSearch, (int)AuctionStatus.Active);
            gvAuctions.DataBind();
            gvEndAuctions.DataSource = AuctionDAL.GetAuctionByString(NameSearch, (int)AuctionStatus.Endtime);
            gvEndAuctions.DataBind();
        }
    }
}